package mega.privacy.android.app.presentation.imagepreview

import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.platform.LocalContext
import androidx.navigation3.runtime.EntryProviderScope
import androidx.navigation3.runtime.NavKey
import mega.privacy.android.navigation.contract.FeatureDestination
import mega.privacy.android.navigation.contract.NavigationHandler
import mega.privacy.android.navigation.contract.TransferHandler
import mega.privacy.android.navigation.contract.transparent.transparentMetadata
import mega.privacy.android.navigation.destination.LegacyImageViewerNavKey
import javax.inject.Inject

fun EntryProviderScope<NavKey>.legacyImageViewerScreen(
    removeDestination: () -> Unit,
) {
    entry<LegacyImageViewerNavKey>(
        metadata = transparentMetadata()
    ) { key ->
        val context = LocalContext.current
        LaunchedEffect(Unit) {
            ImagePreviewActivity.createIntent(
                context = context,
                fileNodeId = key.nodeHandle,
                parentNodeId = key.parentNodeHandle,
                nodeSourceType = key.nodeSourceType
            )?.let { intent ->
                context.startActivity(intent)
            }

            // Immediately pop this destination from the back stack
            removeDestination()
        }
    }
}

